#!/usr/bin/env python3
import time
import gpiod

class LED:
    def __init__(self, chip_number=3, line_offset=22, consumer="robot_led"):
        self.chip = gpiod.Chip(str(chip_number), gpiod.Chip.OPEN_BY_NUMBER)
        self.line = self.chip.get_line(line_offset)
        self.line.request(consumer=consumer, 
                         type=gpiod.LINE_REQ_DIR_OUT, 
                         default_vals=[0])#默认关闭

    def on(self):
        self.line.set_value(1)

    def off(self):
        self.line.set_value(0)

    def __del__(self):
        self.off()
        self.line.release()
        self.chip.close()

